/**
 * 错误处理相关的类型定义和枚举
 */

// 错误类型枚举
export enum ErrorType {
  FILE_NOT_FOUND = 'FILE_NOT_FOUND',
  PERMISSION_DENIED = 'PERMISSION_DENIED',
  INVALID_HISTORY_FORMAT = 'INVALID_HISTORY_FORMAT',
  NETWORK_ERROR = 'NETWORK_ERROR',
  DISK_SPACE_INSUFFICIENT = 'DISK_SPACE_INSUFFICIENT',
  OPERATION_CANCELLED = 'OPERATION_CANCELLED',
  PARSING_ERROR = 'PARSING_ERROR',
  VALIDATION_ERROR = 'VALIDATION_ERROR',
  TIMEOUT_ERROR = 'TIMEOUT_ERROR',
  SEARCH_ERROR = 'SEARCH_ERROR',
  INDEX_NOT_BUILT = 'INDEX_NOT_BUILT',
  INDEX_BUILD_ERROR = 'INDEX_BUILD_ERROR',
  OPERATION_IN_PROGRESS = 'OPERATION_IN_PROGRESS',
  UNKNOWN_ERROR = 'UNKNOWN_ERROR'
}

// 应用错误接口
export interface AppError {
  type: ErrorType
  message: string
  details?: any
  timestamp: Date
  recoverable: boolean
  code?: string
  stack?: string
}

// 操作结果类型
export type OperationResult<T> = {
  success: true
  data: T
} | {
  success: false
  error: AppError
}

// 异步操作结果
export type AsyncOperationResult<T> = Promise<OperationResult<T>>

// 错误严重级别
export enum ErrorSeverity {
  LOW = 'low',
  MEDIUM = 'medium',
  HIGH = 'high',
  CRITICAL = 'critical'
}

// 详细错误信息
export interface DetailedError extends AppError {
  severity: ErrorSeverity
  context?: Record<string, any>
  userMessage?: string
  technicalMessage?: string
  suggestedAction?: string
}

// 错误处理选项
export interface ErrorHandlingOptions {
  showNotification: boolean
  logError: boolean
  reportError: boolean
  retryable: boolean
  maxRetries?: number
}

// 验证错误
export interface ValidationError {
  field: string
  message: string
  code: string
  value?: any
}

// 批量操作错误
export interface BatchOperationError {
  operation: string
  errors: AppError[]
  successCount: number
  failureCount: number
  totalCount: number
}